﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Frogism.Web.Views.Money {
  public partial class MonthProgress : ViewPage<System.Collections.ObjectModel.Collection<Frogism.Core.Balance>> {
    protected override void OnInit(EventArgs e) {
      base.OnInit(e);
      YearRepeater.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(YearRepeater_ItemDataBound);

    }
    protected override void OnLoad(EventArgs e) {
      base.OnLoad(e);
      if(!IsPostBack) {

        List<int> years = ViewData.Model.Select(b => b.BalanceDate.Year).Distinct().ToList<int>();
        YearRepeater.DataSource = years;
        YearRepeater.DataBind();


       
      }
    }

    void YearRepeater_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) {

      System.Web.UI.WebControls.Literal l = (System.Web.UI.WebControls.Literal)e.Item.FindControl("YearLabel");
      if (l != null) l.Text = ((int)e.Item.DataItem).ToString();

      MonthProgressList MonthProgressList1 = (MonthProgressList)e.Item.FindControl("MonthProgressList1");

      MonthProgressList1.Year = ((int)e.Item.DataItem);
      /*
      MonthProgressList.DataSource = ViewData.Model;
        MonthProgressList.DataBind();
       */
    }
  }
}
